//
//  CarDetailTableView.m
//  HeWeiZhiNeng
//
//  Created by 林建 on 2017/12/16.
//  Copyright © 2017年 YanCeyMichael.github.io. All rights reserved.
//

#import "CarDetailTableView.h"
#import "CarDetailCell.h"

static NSString *cellIdentifier = @"CarDetailCell";
@implementation CarDetailTableView

-(instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style{
    self = [super initWithFrame:frame style:style];
    if (self) {
        self.backgroundColor = Color.back;
        self.dataSource = self;
        self.separatorStyle = UITableViewCellSeparatorStyleNone;
        [self registerClass:[CarDetailCell class] forCellReuseIdentifier:cellIdentifier];
    }
    return self;
}

-(void)setDataArr:(NSMutableArray *)dataArr
{
    _dataArr = dataArr;
    [self reloadData];
}

#pragma mark ----- tableView协议方法 -----
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.dataArr.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.dataArr[section] count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CellModel *model  = self.dataArr[indexPath.section][indexPath.row];
    CarDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
        cell = [[CarDetailCell alloc]initWithStyle:0 reuseIdentifier:cellIdentifier];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.model = model;
    UIView *lineV = [[UIView alloc]init];
    lineV.backgroundColor = UIColorFromRGB(0xededed);
    [cell addSubview:lineV];
    if ((indexPath.section == 1 && indexPath.row == 5 ) || indexPath.section == 0 || indexPath.section == 2) {
    } else {
        [lineV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(cell.mas_bottom).offset(-1);
            make.left.mas_equalTo(cell.mas_left);
            make.height.mas_equalTo(1);
            make.right.mas_equalTo(cell.mas_right);
        }];
    }
    return cell;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
